package role

import (
	"context"
	"time"

	"go-weixin/app/usercenter/api/internal/svc"
	"go-weixin/app/usercenter/api/internal/types"
	"go-weixin/app/usercenter/rpc/pb/proto/usercenter"

	"github.com/zeromicro/go-zero/core/logx"
)

type RoleAddPowerLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoleAddPowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleAddPowerLogic {
	return &RoleAddPowerLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleAddPowerLogic) RoleAddPower(req *types.RoleAddPowerReq) (resp *types.RoleAddPowerResp, err error) {
	ctx, cannFunc := context.WithTimeout(context.Background(), 5*time.Second)
	defer cannFunc()
	_, err = l.svcCtx.UserRpc.RoleAddPower(ctx, &usercenter.RoleAddPowerReq{
		RoleId:  req.RoleId,
		PowerId: req.PowerId,
	})
	return
}
